package com.diors.game.engine.arpg.skill.effect;

import com.diors.game.engine.arpg.fight.FightEngine;
import com.diors.game.engine.arpg.fight.FightFormula;
import com.diors.game.engine.arpg.fight.FightObject;
import com.diors.game.engine.arpg.fight.attr.object.AttrObject;
import com.diors.game.engine.arpg.object.AbstractObject;
import com.diors.game.engine.arpg.skill.model.SkillEffectModel;
import com.diors.game.engine.arpg.skill.trigger.SkillTriggerFactory;

/**
 * 攻击效果
 * @author	darren.ouyang <ouyang.darren@gmail.com>
 * @date	2013年12月3日
 * @version 1.0
 * @copyright Copyright (c) 2013, darren.ouyang
 */
public class AttackEffect extends AbstractEffect
{

	@Override
	protected void castImpl(AbstractObject attack, AbstractObject target, SkillEffectModel model) 
	{
		AttrObject attackAt = attack.getAttr();
		AttrObject targetAt = target.getAttr();
		int harm = 0;
		
		float luck = FightFormula.getInstance().luck(attackAt);
		float block = FightFormula.getInstance().block(attackAt, targetAt);
		float crit = FightFormula.getInstance().crit(attackAt, targetAt);
		FightObject fight = new FightObject(luck, block, crit, 1f, 1f);
		
		// PVP or PVE 走不同的计算公式
		if (FightEngine.isPvp(attack, target))
			harm = FightFormula.getInstance().pvpHarm(attackAt, targetAt, fight);
		else
			harm = FightFormula.getInstance().pveHarm(attackAt, targetAt, fight);
		
		FightEngine.subtractHpMp(harm, 0);
		
		// 触发攻击命中效果
		SkillTriggerFactory.attackTrigger(attack, target, model);
	}

}
